<template>
	<view  class="container">
		<view>
			<uni-card  v-if="item.schedule !==100" v-for="item in examineReportList" :key="item.id">
				<view style="display: flex;justify-content: space-between;align-items: center;">
					<view>{{item.taskName}}</view>
					<uni-tag style="width: 100rpx;text-align: center;" text="上报" :inverted="true"
						@click="gopath(item)"></uni-tag>
				</view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import {
		listExamineReport,
		getExamineReport,
		delExamineReport,
		addExamineReport,
		updateExamineReport,
	} from "@/api/comp/examineReport";
	import {
		listExamineGroupPerson
	} from "@/api/comp/examineGroupPerson";
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				date: new Date(),
				examineReportList: [],
				personsId: [],
				persons:[],
				checkedPersons:[],
				userId: ''
			}
		},
		onLoad() {
			this.getList()
		},
		computed: {
			...mapState({
				name: (state) => state.user.name,
				userInfo: (state) => state.user.userInfo,

			}),
		},
		methods: {
			getList() {
				listExamineReport().then(res => {
					res.rows.map(item => {
						if (item.groupId) {
							this.examineReportList.push(item)
						}
					})
				})
				this.userId = this.userInfo.id
			},
			backClick() {
				uni.navigateBack()
			},
			async gopath(row) {
				if (row.objId == null) {
					this.$u.toast('请先关联考评小组')
					return;
				}
				await this.initGroupPersonList(row.groupId)
				setTimeout(() => {
					if (!this.personsId.includes(this.userId)) {
						this.$u.toast(
							"此任务已由" + row.groupName + "组关联，其他组员无法上报"
						);
						return;
					}

					if (this.userId != row.userId && row.userId != null) {
						this.$message.error(
							"此任务已由" + row.nickName + "上报，其他人无法再次上报"
						);
						return;
					}
					uni.navigateTo({
						url: `/pages/gardens/khdj/report?id=${row.id}&groupName=${row.groupName}&objName=${row.objName}`,
					});
				})
			},
			async initGroupPersonList(groupId) {
				this.persons = [];
				this.checkedPersons = [];
				this.personsId = [];
				if (groupId) {
					let response = await listExamineGroupPerson({
						groupId: groupId
					})
					this.personsId = response.rows.map(item=>{
						return item.userId
					})
				}
			},
		}
	}
</script>

<style lang="scss">
	$nav-height: 30px;

	.box-bg {
		background-color: #F5F5F5;
		padding: 5px 0;
	}

	.city {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		// width: 160rpx;
		margin-left: 4px;
	}

	.input-uni-icon {
		line-height: $nav-height;
	}
</style>